package com.oromwin.repos.common;

import java.io.File;
import java.io.Serializable;

import org.apache.commons.logging.Log;

public class FileDescriptor implements Serializable {
    private transient Log log = Logger.getLog(FileDescriptor.class);
    private static final long serialVersionUID = 1045592297562017603L;
    
    private String volumeId = null; // logical-group-id
    private String mediaId = null; // physical-repository-id
    private String fileId = null; // physical-file-id
    private File file = null;
    
    public FileDescriptor(String vid, String mid, String fname) throws ReposException 
    {
        try {
            volumeId = vid;
            mediaId = mid;
            fileId =  Common.UniqueId.generate();
            file = new File(mid + fname);
        } catch (NullPointerException e) {
            String message = String.format("Illegal pathString, {%s}", mid + fname);
            throw ReposException.create(log, e, message);
        }
    }

    public long getFileLength() {
        return file.length();
    }
    
    public String getFilename() {
        return file.toString();
    }

    public File getFile() {
        return file;
    }
    
    public void setFile(File f) {
        file = f;
    }

    public String getVolumeId() {
        return volumeId;
    }

    public String getMediaId() {
        return mediaId;
    }

    public String getFileId() {
        return fileId;
    }
}
